﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Fadd.IO.Consoles;
using Fadd.Logging.Filters;
using Fadd.Logging.Targets;

namespace Fadd.Logging
{
    public class SimpleLogManager : ILogManager
    {
        private ILogger _logger;
        private static SimpleLogManager _instance = null;
        private static List<ILogFilter> _filters = new List<ILogFilter>();
        private static List<ILogTarget> _targets = new List<ILogTarget>();

        private SimpleLogManager()
        {
            _logger = new Logger(_filters, _targets);
        }

        public static void AddFile(string fileNameWithoutExtension, FileConfiguration configuration)
        {
            if (_instance == null)
            {
                _instance = new SimpleLogManager();
                LogManager.Assign(_instance);
            }

            _targets.Add(new PaddedFileTarget(fileNameWithoutExtension, configuration));
        }

        public static void AddFile(string fileNameWithoutExtension)
        {
            var configuration = new FileConfiguration();
            configuration.Path = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
            configuration.DaysToKeep = 7;
            AddFile(fileNameWithoutExtension, configuration);
        }

        public static void AddConsole(bool createConsole)
        {
            if (_instance == null)
            {
                _instance = new SimpleLogManager();
                LogManager.Assign(_instance);
            }

            _targets.Add(new ConsoleTarget());
            if (!ConsoleDetector.HasOne && createConsole)
                ConsoleDetector.CreateConsole();
        }

        public static void AddFilter(ILogFilter logFilter)
        {
            
        }


        public ILogger GetLogger(Type type)
        {
            return _logger;
        }
    }
}
